package cn.chia.back.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

import cn.chia.back.dao.IAdminDAO;
import cn.chia.pojo.TblUser;

@Component
public class AdminDAOImpl extends HibernateDaoSupport implements IAdminDAO {
	
	@Autowired
	public AdminDAOImpl(HibernateTemplate hibernateTemplate){
		super.setHibernateTemplate(hibernateTemplate);
	}

	public void doCreate(TblUser vo) throws Exception {
		// TODO Auto-generated method stub

	}

	public void doRemove(Integer id) throws Exception {
		// TODO Auto-generated method stub

	}

	public void doUpdate(TblUser vo) throws Exception {
		// TODO Auto-generated method stub

	}

	public List<TblUser> findAll() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public List<TblUser> findAll(int pageNo, int pageSize, String keyword,
			String column) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public TblUser findById(Integer id) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public int getAllCount(String keyword, String column) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	@SuppressWarnings("unchecked")
	public TblUser login(TblUser tuser) throws Exception {
		String hql = "FROM TblUser AS tu WHERE tu.userName=? AND tu.password=?";
		List<TblUser> allUser = super.getHibernateTemplate().find(hql, tuser.getUserName(), tuser.getPassword());
		TblUser loginUser = new TblUser();
		if(allUser != null && allUser.size()>0){
			loginUser = allUser.get(0);
			tuser.setWorkCode(loginUser.getWorkCode());
		}
		return loginUser;
	}

	

}
